package com.sjm.learn.lock;

/**
 * @Description:自增测试案例1
 * @Author：shenjm25081
 * @Date：17:21 2019-2-20
 */
public class AtomicIntegerDemo2 {

    private static final int THREADS_CONUT = 20; //线程数
    public static volatile int count = 0;

    public static void increase() {
        count++;
    }

    public static void main(String[] args) {
        Thread[] threads = new Thread[THREADS_CONUT];
        for (int i = 0; i < THREADS_CONUT; i++) {
            threads[i] = new Thread(new Runnable() {
                @Override
                public void run() {
                    for (int i = 0; i < 1000; i++) {
                        increase();
                    }
                }
            });
            threads[i].start();
        }

        while (Thread.activeCount() > 2) {
            Thread.yield();
        }
        System.out.println(count);
    }
}
